/**
 * Copyright 2014  XCL-Charts
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * @Project XCL-Charts
 * @Description Android图表基类库
 * @author XiongChuanLiang<br></br>(xcl_168@aliyun.com)
 * @Copyright Copyright (c) 2014 XCL-Charts (www.xclcharts.com)
 * @license http://www.apache.org/licenses/  Apache v2 License
 * @version 1.0
 */
package com.demo.xclcharts.view1

import android.content.Context
import android.graphics.Color
import android.util.AttributeSet
import android.util.Log
import com.gitee.wsl.common.chart.ChartEnum
import com.gitee.wsl.common.chart.sample.pie.model.PieData
import com.gitee.wsl.common.chart.sample.rose.RoseChart
import com.gitee.wsl.ext.base.setAll
import java.util.LinkedList

/**
 * @ClassName RoseChart01View
 * @Description  南丁格尔玫瑰图 的例子
 * @author XiongChuanLiang<br></br>(xcl_168@aliyun.com)
 */
class RoseChart01View : DemoView {
    private val TAG = "RoseChart01View"
    private val chart = RoseChart()
    var roseData = LinkedList<PieData>()

    constructor(context: Context) : super(context) {
        // TODO Auto-generated constructor stub
        initView()
    }

    constructor(context: Context, attrs: AttributeSet?) : super(
        context, attrs
    ) {
        initView()
    }

    constructor(context: Context, attrs: AttributeSet?, defStyle: Int) : super(
        context, attrs, defStyle
    ) {
        initView()
    }

    private fun initView() {
        chartDataSet()
        chartRender()
        //綁定手势滑动事件
        this.bindTouch(this, chart)
    }


    private fun chartRender() {
        try {

            //设置绘图区默认缩进px值
            val ltrb = pieDefaultSpadding
            /*chart.setPadding(
                ltrb[0].toFloat(),
                ltrb[1].toFloat(),
                ltrb[2].toFloat(),
                ltrb[3].toFloat()
            )*/

            //背景 
            chart.isShowBackground=true
            chart.backgroundColor=Color.BLACK

            //数据源
            chart.dataSet = roseData

            //设置标题
            chart.setTitle("南丁格尔玫瑰图","(XCL-Charts)")

            chart.plotTitle.titlePaint.color = Color.WHITE
            chart.plotTitle.subtitlePaint.color = Color.WHITE

            //设置标签显示位置,当前设置标签显示在扇区中间
            chart.labelStyle=ChartEnum.SliceLabelStyle.OUTSIDE
        } catch (e: Exception) {
            // TODO Auto-generated catch block
            Log.e(TAG, e.toString())
        }
    }

    private fun chartDataSet() {
        //设置图表数据源

        //PieData(标签，百分比，在饼图中对应的颜色)
        roseData.add(
            PieData(
                "PostgreSQL","40", 40f, Color.rgb(77, 83, 97)

            )
        )
        roseData.add(
            PieData(
                "Sybase", "40",50f, Color.rgb(148, 159, 181)

            )
        )
        roseData.add(
            PieData(
                "DB2", "40",60f, Color.rgb(253, 180, 90)

            )
        )
        roseData.add(
            PieData(
                "国产及其它", "40",35f, Color.rgb(52, 194, 188)

            )
        )
        roseData.add(
            PieData(
                "SQL Server", "40",70f, Color.rgb(39, 51, 72)

            )
        )
        roseData.add(
            PieData(
                "DB2", "40",80f, Color.rgb(255, 135, 195)

            )
        )
        roseData.add(
            PieData(
                "Oracle","40", 90f, Color.rgb(215, 124, 124)
            )
        )
    }

    /*override fun render(canvas: Canvas) {
        try {
            canvas.drawColor(Color.BLACK)
            chart.render(canvas)
        } catch (e: Exception) {
            Log.e(TAG, e.toString())
        }
    }*/
}